<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>可可文章管理系统</title>
<link href="../template/css/ke.css" rel="stylesheet" type="text/css" />
<script src="http://img.kekenet.com/statics/js/jquery.min.js"></script>
</head>
<body>
<!-- main -->
<div>
<div class="issCont">
  <div class="SelectTab">
    <h1 class="SelectTab_title">选择栏目：</h1>
    <p class="gree">
	{{foreach from=$sub_cats item=c}}
	  <a href="../index.php/category.index?pid={{$pid}}&cid={{$c['catid']}}">{{$c['catname']}}</a> | 
	{{/foreach}}
	</p>
	{{if $cil_cats}}
    <p class="blue">
	{{foreach from=$cil_cats item=c}}
	  <a href="../index.php/category.index?pid={{$pid}}&cid={{$cid}}&catid={{$c['catid']}}">{{$c['catname']}}</a> | 
	{{/foreach}}
	</p>
	{{/if}}
  </div>
  
  <div class="table">
    <!-- <div class="table_column">
      <h1 class="tc_title">创意生活 (共34篇)</h1>
      <div class="search"><input name="" type="text" class="sendbox_search" /><input name="" type="button" value="搜索" class="botton_search" /></div>
    </div> -->
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td class="table_header"><input type="checkbox" value="" id="check_box" onclick="selectall('check_box','sel[]');" /></td>
		<td class="table_header">ID</td>
        <td class="table_header">标题</td>
        <td align="center" class="table_header">编辑</td>
        <td align="center" class="table_header">发布人</td>
        <td align="center" class="table_header">发布时间</td>
        <td align="center" class="table_header">预览</td>
      </tr>
      
      {{foreach from=$artlist item=c}}
      <tr onmouseOver="this.style.backgroundColor='#e9f0ff';" onmouseout="this.style.backgroundColor='#fff';">
        <td><input type="checkbox" name="sel[]" value="{{$c['id']}}" /></td>
        <td>{{$c['id']}}</td>
		<td><a href="../index.php/category.index?pid={{$pid}}&cid={{$c['cat_info']['parentid']}}&catid={{$c['cat_info']['catid']}}" class="link_gree">[{{$c['cat_info']['catname']}}]</a><a href="../index.php/detail.edit?pid={{$c['cat_info']['parentid']}}&id={{$c['id']}}"> {{$c['title']}}</a></td>
        <td align="center"><a href="../index.php/detail.edit?pid={{$c['cat_info']['parentid']}}&id={{$c['id']}}"><img src="http://img.kekenet.com/cms/images/icon_edit.gif" width="13" height="13" /></a></td>
        <td align="center">{{$c['username']}}</td>
        <td align="center">{{date('Y-m-d H:i:s',$c['inputtime'])}}</td>
        <td align="center"><a href="../index.php/detail.index?id={{$c['id']}}&do=preview" target="preview"><img src="http://img.kekenet.com/statics/images/admin_img/onSuccess.gif" width="22" height="22" /></a></td>
      </tr>
      {{/foreach}}
    </table>
    
    <table width="100%" border="0" cellspacing="0" cellpadding="0" class="table_footer">
      <tr>
        <td><input type="checkbox" value="" id="check_box_1" onclick="selectall('check_box_1','sel[]');" class="input_none" /></td>
        <td><a style="color:#fff;" target="preview" href="../index.php/category.index?pid={{$pid}}&cid={{$cid}}&catid={{$catid}}&do=preview">预览当前栏目</a></td>
        <td><input id="make_current_btn" type="button" value="生成当前栏目" /></td>
        <td><input id="make_select_btn" type="button" value="生成选中的内容" /></td>
        <td><input id="make_all_btn" type="button" value="生成当前栏目内容" /></td>
      </tr>
    </table>
    
	{{if $pages}}
    <div class="paging">
	{{foreach from=$pages item=c}}
	  <a href="../index.php/category.index?pid={{$pid}}&cid={{$cid}}&catid={{$catid}}&page={{$c}}">{{$c}}</a> 
	{{/foreach}}
	 <strong>{{$page}}/{{$max_page}}</strong>
	</div>
	{{/if}}
  </div>

  <!-- <div id="output_info" style="height: 100px; clear:both; overflow:auto;" >
    <div id="title"></div>
    <div id="list"></div>
  </div> -->
  
  <iframe id="preview" name="preview" src="about:blank" width="100%" height="400px" scrolling="no" frameborder="0"></iframe>
</div>

<script>
function clear_output() {
	ShowDIV();
	//$('#output_info').show();
	$('#output_info #title').html('');
	$('#output_info #list').html('');
}

/*function out_hide() {
	$('#output_info').hide(3000);
}*/

function ShowDIV() {
	$('#BgDiv', parent.document).css({ display: "block" });
}

function hiderDIV(){
	$('#BgDiv', parent.document).css({ display: "none" });
	$('#output', parent.document).css({ display: "none" });
}

function show_output(){
	var data = $('#output_info').html();
	$('#output', parent.document).css({ display: "block" });
	$('#output', parent.document).html(data);
}

function call(url, callback) {
	$.getJSON(url, callback);
}
function make_static_content(ids) {
	var ids_length = ids.length;
	$('#output_info #title').html('生成<span id="maked_cnt">0</span> / ' + ids_length + '个页面');
	
	function make() {
		var xids = ids.slice(0, 5);
		$(xids).each(function(k, v){
			call('../index.php/detail.index?do=makestatic&id=' + v, function(data){
				if(data.status==1) {
					var cnt = parseInt($('#maked_cnt').html());
					$('#maked_cnt').html(++cnt);
					$('#output_info #list').prepend('<p>' + data.id + ' 生成成功.</p>');
				}
			});
		});
		ids = ids.slice(5);
		if(ids.length > 0) {
			setTimeout(function(){ make() }, 300);
		}
	}
	make();
}
$(document).ready(function(){
	$('#make_current_btn').click(function(){
		clear_output();
		$('#output_info #title').html('生成{{$caid}}');
		call('../index.php/category.index?pid={{$pid}}&cid={{$cid}}&catid={{$catid}}&do=makestatic', function(data){
			if(data.status==1) {
				$('#output_info #list').prepend('<p>' + data.catid + ' 生成成功.</p>');
				if(typeof(data.max_page) != 'undefined') {
					$('#output_info #list').prepend('<p>' + data.catid + ' 生成相关分页, 共' + data.max_page + '页.</p>');
					for(var page = 2; page <= data.max_page; page++) {
						call('../index.php/category.index?pid={{$pid}}&cid={{$cid}}&catid={{$catid}}&do=makestatic&page=' + page, function(data){
							$('#output_info #list').prepend('<p>第 ' + data.page + ' 页 生成成功.</p>');
						});
					}
				}
			}
		});
		show_output();
	});
	$('#make_all_btn').click(function(){
		clear_output();
		call('../index.php/category.get_index?catid={{$caid}}', function(data){
			make_static_content(data.ids);
		});
		show_output();
	});
	$('#make_select_btn').click(function(){
		clear_output();
		var ids = [];
		$('input[name=sel[]][checked]').each(function(){
			ids.push($(this).val());
		});
		make_static_content(ids);
		show_output();
	});	
});

function selectall(id,name) {
	if ($("#"+id).attr("checked")==false) {
		$("input[name='"+name+"']").each(function() {
			this.checked=false;
		});
	} else {
		$("input[name='"+name+"']").each(function() {
			this.checked=true;
		});
	}
}
</script>
</div>
<!-- /main -->

<div class="PromptBox" id="output_info" style="clear:both; overflow:auto;display:none;z-index:1000;">
  <div class="pb_column"><a href="javascript:hiderDIV();" class="pb_c_close">×</a>提示</div>
  <div class="pb_cont">
    <h1><img src="../template/images/icon_prompt.gif" width="28" height="30" align="absmiddle" />生成相关内容</h1>
    <div id="title"></div>
    <div id="list"></div>
  </div>
</div>
</body>
</html>